﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlexiCommerce.Components;
using NUnit.Framework;

namespace FlexiCommerce.Tests.Persistence.NH
{
    [TestFixture]
    public class LanguageQueryableTests : DatabasePreparingBase
    {
        #region SetUp

        Language english;
        Language spanish;

        [TestFixtureSetUp]
        public override void TestFixtureSetUp()
        {
            try
            {


                base.TestFixtureSetUp();

                CreateSpanishItem();
                CreateEnglishItem();


            }
            catch (Exception)
            {

            }
        }

        [SetUp]
        public override void SetUp()
        {
            engine.Persister.Dispose();
        }

        private void CreateEnglishItem()
        {
            english = new Language() { Culture = Culture.English };
            engine.Persister.Save(english);
        }

        private void CreateSpanishItem()
        {
            spanish = new Language() { Culture = Culture.Spanish };
            engine.Persister.Save(spanish);
        }

        #endregion

        [Test]
        public void ByPropertyID()
        {
            Language item = Find.Languages.SingleOrDefault(i => i.ID == english.ID);

            Assert.AreEqual(english, item);
        }

        [Test]
        public void ByPropertyCulture()
        {
            Language item = Find.Languages.SingleOrDefault(i => i.Culture == english.Culture);

            Assert.AreEqual(english, item);
        }

    }
}
